<template>
    <div class="orders">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-table :data="result.goods" border style="width: 100%;margin-top:20px;">
            <el-table-column type="index" label="#" width="48"></el-table-column>
            <el-table-column prop="order_number" label="订单编号" width="300"></el-table-column>
            <el-table-column prop="order_price" label="订单价格" width="80"></el-table-column>
            <el-table-column prop="pay_status" label="是否付款" width="100">
                <template slot-scope="scope">
                    <el-tag v-if="scope.row.pay_status==0" type="danger">未付款</el-tag>
                    <el-tag v-else type="success">已付款</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="is_send" label="是否发货"></el-table-column>
            <el-table-column prop="create_time" label="下单时间">
                <template slot-scope="scope">{{scope.row.create_time | createTime}}</template>
            </el-table-column>
            <el-table-column label="操作">
                <el-button type="primary" size="mini" icon="el-icon-edit" plain></el-button>
            </el-table-column>
        </el-table>
        <el-pagination style="margin-top:20px"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="+ordersPage.pagenum"
            :page-sizes="[10,20,30,40]"
            :page-size="+ordersPage.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="result.total">
        </el-pagination>
    </div>
</template>
<script>
import {orderList} from '../../http/api'
export default {
    data() {
        return {
            ordersPage: {
                pagenum: this.$route.query.pagenum || 1,
                pagesize: this.$route.query.pagesize || 10
            },
            result: {}
        }
    },
    methods:{
        async orderList(){
            const res = await orderList({
                query: '',
                pagenum: this.ordersPage.pagenum,
                pagesize: this.ordersPage.pagesize,
                user_id: '',
                pay_status: '',
                is_send: '',
                order_fapiao_title: [],
                order_fapiao_company: '',
                order_fapiao_content: '',
                consignee_addr: ''
            });
            this.result = res;
            console.log(res.goods);
        },
        handleSizeChange(num) { //每页显示条数发生变化时触发
            this.ordersPage.pagesize=num;
            this.orderList();
        },
        handleCurrentChange(num) { //页码发生变化
            this.ordersPage.pagenum=num;
            this.orderList();
        },
    },
    watch:{
        ordersPage:{ //监听页码并传入路径
            deep: true,
            handler(val){
                this.$router.push({query: val})
            }
        }
    },
    created(){
        this.orderList();
    },
    filters:{
        createTime(item){
            var date = new Date(item);
            var month = date.getMonth()+1;
            item = date.getFullYear() + '-' + ('0'+month) + '-'+ date.getDate()+'T';
            return item;
        }
    }
}
</script>
<style lang="scss" scoped>
    
</style>